package com.hanrui.android.fragment;


import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hanrui.android.R;
import com.hanrui.android.activity.AddressListActivity;
import com.hanrui.android.activity.MainActivity;
import com.hanrui.android.adapter.MobileAdapter;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.constant.LoadType;
import com.hanrui.android.model.CompanyListBean;
import com.hanrui.android.net.contract.addresslist.CompanyContract;
import com.hanrui.android.net.presenter.addresslist.CompanyPresenter;
import com.hanrui.android.widget.SearchEditText;

import javax.inject.Inject;

import butterknife.BindView;


/**
 * 通讯录
 * Created by zhengwei on 2018/1/31.
 */

public class MobileFragment extends BaseFragment<CompanyPresenter> implements CompanyContract.View, BaseQuickAdapter.OnItemClickListener {


    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    @Inject
    MobileAdapter adapter;
    @BindView(R.id.searchEditText)
    SearchEditText searchEditText;

    MainActivity mActivity;

    String name = "";

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mobile;
    }

    @Override
    protected void initInjector() {
        mFragmentComponent.inject(this);
    }

    @Override
    protected void initView(View view) {

        mActivity = (MainActivity) getActivity();

        mPresenter.empEmployeeList(getActivity(),name,"2");

        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecyclerView.setAdapter(adapter);
        adapter.setEmptyView(getNoDataView(mRecyclerView));
        adapter.setOnItemClickListener(this);


        searchEditText.setOnSearchClickListener(new SearchEditText.OnSearchClickListener() {
            @Override
            public void onSearchClick(View view, String keyword) {

                name = searchEditText.getText().toString();
                mPresenter.empEmployeeList(getActivity(),name,"2");

            }
        });
    }


    //实例化
    public static MobileFragment newInstance() {
        return new MobileFragment();
    }


    @Override
    public void empEmployeeList(CompanyListBean data) {

        setLoadDataResult(null,adapter,data.getIsAttendList(), LoadType.TYPE_REFRESH_SUCCESS,false);

    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

        CompanyListBean.IsAttendListBean bean = (CompanyListBean.IsAttendListBean) adapter.getItem(position);
        AddressListActivity.start(mActivity,bean.getId());

    }
}
